package cn.jilian.sys.service.impl;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jilian.common.dto.Filters;
import cn.jilian.common.dto.PageInfo;
import cn.jilian.common.dto.PageResult;
import cn.jilian.common.dto.SortInfo;
import cn.jilian.dao.UnitDAO;
import cn.jilian.entity.Unit;
import cn.jilian.sys.service.UnitService;

@Service
public class UnitServiceImpl implements UnitService {

	@Autowired
	private UnitDAO unitDAO;
	
	@Override
	public Unit findBySid(long id) {
		return unitDAO.findOne(id);
	}

	@Override
	public long add(Unit unit) {
		Unit u=unitDAO.findByText(unit.getText());
		if(u!=null) {
			return -1;
		}
		
		unit=unitDAO.save(unit);
		
		return unit.getId();
	}

	@Override
	public int save(Unit unit) {
		
		unit= unitDAO.save(unit);
		return 1;
	}

	@Override
	public Unit findByName(String name) {
		Unit unit=unitDAO.findByText(name);
		return unit;
	}

	@Override
	public PageResult<Unit> query(PageInfo pageInfo, SortInfo sortInfo, List<Filters> filters) {
		
		return null;
	}

	@Override
	public Collection<Unit> findByFid(Long id) {
		
		return unitDAO.findByFidOrderBySeq(id);
	}

	@Override
	public void delete(Long id) {
		unitDAO.delete(id);
	}
}
